package com.example.joysinfo.lkc.util;

import android.content.SharedPreferences;

import com.example.joysinfo.lkc.App;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/4/27.
 */
public class Sharedpreference {

    public static final SharedPreferences.Editor sd = App.getInstance().getSharedPreferences("dajiayiguan", 1).edit();;
    public static final SharedPreferences sp = App.getInstance().getSharedPreferences("dajiayiguan", 1);

    public static void setSign(String accessKey){
        sd.putString("sign",accessKey);
        sd.commit();
    }
    public static String getSign(){
        String access=sp.getString("sign", "");
        return access;
    }

    public static void setAccount(String accessKey){
        sd.putString("account",accessKey);
        sd.commit();
    }
    public static String getAccount(){
        String access=sp.getString("account", "");
        return access;
    }

    public static void setPas(String accessKey){
        sd.putString("passwd",accessKey);
        sd.commit();
    }
    public static String getPas(){
        String access=sp.getString("passwd", "");
        return access;
    }

    public static void setUserid(String accessKey){
        sd.putString("userid",accessKey);
        sd.commit();
    }
    public static String getUserid(){
        String access=sp.getString("userid", "");
        return access;
    }

    public static void setType(String accessKey){
        sd.putString("type",accessKey);
        sd.commit();
    }
    public static String getType(){
        String access=sp.getString("type", "");
        return access;
    }

    public static void saveArray(ArrayList<String> sKey) {

        sd.putInt("Status_size",sKey.size()); /*sKey is an array*/
        for(int i=0;i<sKey.size();i++) {
            sd.remove("Status_" + i);
            sd.putString("Status_" + i, sKey.get(i));
        }

        sd.commit();
    }
    public static ArrayList<String> loadArray() {

        ArrayList<String> sKey=new ArrayList<String>();

        int size = sp.getInt("Status_size", 0);

        for(int i=0;i<size;i++) {
            sKey.add(sp.getString("Status_" + i, null));
        }
        return sKey;
    }
}
